package com.lk.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.lk.activity.R;
import com.lk.model.ThemeMainInfo;

import java.util.List;

/**
 * Created by liu kun on 2018/8/1 0001.
 */

public class MenuListAdapter extends RecyclerView.Adapter<MenuListAdapter.Holder> {
    private List<ThemeMainInfo> menuLists;
    private Context context;
    public MenuListAdapter(List<ThemeMainInfo> menuLists,Context context){
        this.menuLists=menuLists;
        this.context=context;
    }
    @Override
    public Holder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(context).inflate(R.layout.menu_item_layout,null);
        Holder holder=new Holder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(Holder holder, int position) {
        ThemeMainInfo info = menuLists.get(position);
        holder.mMenuItemTv.setText(info.getName());
        Glide.with(context)
                .load(info.getThumbnail())
                .error(R.drawable.logo)
                .into(holder.mMenuItemIv);
    }

    @Override
    public int getItemCount() {
        return menuLists.size();
    }

    class Holder extends RecyclerView.ViewHolder{
        ImageView mMenuItemIv;
        TextView mMenuItemTv;
        public Holder(View itemView) {
            super(itemView);
            mMenuItemIv= (ImageView) itemView.findViewById(R.id.mMenuItemIv);
            mMenuItemTv= (TextView) itemView.findViewById(R.id.mMenuItemTv);
        }
    }
}
